# Contributor: messense <messense@icloud.com>
# Maintainer: messense <messense@icloud.com>
pkgname=py-spy
pkgver=0.3.14
pkgrel=3
pkgdesc="Sampling profiler for Python programs"
url="https://github.com/benfred/py-spy"
arch="aarch64 x86_64 ppc64le" # limited by rust
license="MIT"
makedepends="cargo zlib-dev libunwind-dev xz-dev cargo-auditable"
checkdepends="python3 bash"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/benfred/py-spy/archive/v$pkgver.tar.gz
	$pkgname-fix-check.patch::https://github.com/benfred/py-spy/commit/e6053b5f6f7440451ed0c7607ec1431fa17d972a.diff
	"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --release --frozen

	./target/release/py-spy completions bash > $pkgname.bash
	./target/release/py-spy completions fish > $pkgname.fish
	./target/release/py-spy completions zsh > $pkgname.zsh
}

check() {
	# Some tests need additional privileges
	cargo test --frozen -- \
		--skip test_busy_loop \
		--skip test_delayed_subprocess \
		--skip test_local_vars \
		--skip test_long_sleep \
		--skip test_negative_linenumber_increment \
		--skip test_recursive \
		--skip test_subprocesses \
		--skip test_subprocesses_zombiechild \
		--skip test_thread_names \
		--skip test_thread_reuse \
		--skip test_unicode
}

package() {
	install -Dm0755 target/release/$pkgname -t "$pkgdir"/usr/bin
	install -Dm0644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname
}

sha512sums="
f079b002248a033eac3b93723fd267e6cbdb415ac3172ace0d14eb9cd87a1e4adf471eeec641f9644abe8a4fab43b48db7440b4b1242ea18e02bcc574104d303  py-spy-0.3.14.tar.gz
2b927080cd953facc47994b665bfa3d1c47552b549673b11b047db21bc773a53d10faffd26482c3f9825fae8f0f87d387cb9e602898288cf88b7d5a0a8589eb3  py-spy-fix-check.patch
"
